<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link href="../css/xzx_style.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../style/fjol_style.css"/>
		<link rel="stylesheet" type="text/css" href="../style/xol_style.css"/>
	</head>

	<body>
		<script src="../js/mui.min.js"></script>
		<script src="../js/common.util.js"></script>
		<script src="../js/network.js"></script>
		<script src='../js/md5.js'></script>
		<script src="../js/xzx.open.js"></script>
		<script src="../js/enum.util.js"></script>
		<script src="../js/date.time.util.js"></script>

		<header class="mui-bar mui-bar-nav xa-nav newbgRed">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<div class="mui-title">交易进度</div>
		</header>
		<div class="mui-content">
			<div class="mui-scroll-wrapper xzx-pt44">
				<div class="mui-scroll">
					<div class="xa-trade-header">
						交易信息
					</div>
					<div class="xa-trade-info">
						<div>
							<span id="txtStatus" class="xa-trade-state">[未成交]</span>
							<span id="txtTitle" class="xa-trade-info-value">丰泽区西湖豪园16号楼1201室</span>
						</div><br />
						<div>
							<span id="txtCollectNum" class="xa-trade-num">0</span>
							<span class="xzx-text-gray xzx-text-80">人关注&nbsp;&nbsp;&nbsp;&nbsp;</span>

							<!--<span id="txtBargainNum" class="xa-trade-num">0</span>
							<span class="xzx-text-gray xzx-text-80">人砍价</span>-->
						</div>
						<div>
							<span class="xa-trade-info-key xa-trade-price">成交金额</span>
							<span id="txtPrice" class="xa-trade-info-value xzx-text-cell-red-bold">&nbsp;</span>
						</div>
						<div>
							<span class="xa-trade-info-key">成交时间</span>
							<span id="txtTime" class="xa-trade-info-value">2017年06月26日15:21:51</span>
						</div>
						<div>
							<span class="xa-trade-info-key">交易进度</span>
							<span id="txtTradeState" class="xa-trade-info-value">支付定金</span>
						</div>
					</div>
					<div class="xa-trade-header">
						服务专员
					</div>
					<div class="xa-trade-info">
						<img src="../images/icon_default_header@2x.png" class="personal-header-circle" />
						<div class="personal-user-info">
							<div id="txtBuyerName" class="personal-user-name"></div>
							<div class="personal-user-phone">
								<span id="txtBuyerMobile"></span>
								<button id="btnCallBuyer" type="button" class="mui-btn xa-btn-green xa-trade-connect-button mui-hidden">联系经纪人</button>
							</div>
						</div>
					</div>
					<div class="xa-trade-header xa-trade-state-title">
						交易进度
					</div>
					<div class="xa-trade-info xz-trade-state-content">
						
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript">
			var _tradingStateId;//交易进度状态ID
			var _houseModel;
			var _houseSaleDetail;
			var _kind;
			mui.init();
			mui('.mui-scroll-wrapper').scroll({
				bounce: false,
				indicators: false, //是否显示滚动条
				deceleration: mui.os.ios ? 0.003 : 0.0009 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
			});
			mui.plusReady(function(){
				var wv = plus.webview.currentWebview();
				_houseModel = wv.houseModel;
				_kind = wv.kind;
//				console.log(JSON.stringify(_houseModel));
				if(_houseModel){
					setupHouseTradeInfoToPage(_houseModel);
				}
				if(_houseModel&&_houseModel.tradingStateId){
					_tradingStateId = _houseModel.tradingStateId;
				}else{
					_tradingStateId = 0;
				}
				var util = enumUtils;
				var listTradeState = util.getTradeStateData();
				var divContent = document.querySelector('.xz-trade-state-content');
				if(_kind != 3){
					divContent.insertBefore(createTradeStateFragment(listTradeState),divContent.firstChild);
				}else{
					divContent.classList.add('mui-hidden');
					document.querySelector('.xa-trade-state-title').classList.add('mui-hidden');
				}
				
				
				if(_tradingStateId>0){
					getTradeDetail(function(){
						
					},function(){
						
					});
				}
				
			});
			
			var setupHouseTradeInfoToPage = function(houseModel,tradeModel){
				var houseParam = [{
					key:'houseId',
					value:houseModel.id
				}];
				
				
				fjNetwork.get('fjzx/common/house-sale-detail.json',houseParam,function(data){
//					console.log(JSON.stringify(data));
					_houseSaleDetail = data.houseSaleDetail;
//					console.log(_houseSaleDetail.salemanRealname);
				document.querySelector('#txtBuyerName').innerHTML = _houseSaleDetail.salemanRealname?_houseSaleDetail.salemanRealname:'签订合同后安排专员服务';
				document.querySelector('#txtBuyerMobile').innerHTML = _houseSaleDetail.salemanMobile?_houseSaleDetail.salemanMobile:'';
				if(!_houseSaleDetail.salemanMobile){
					document.querySelector('#btnCallBuyer').classList.add('mui-hidden');
				}else{
					document.querySelector('#btnCallBuyer').classList.remove('mui-hidden');
				}
				},function(msg){
					mui.toast(msg);
				});
				document.querySelector('#txtStatus').innerHTML = '['+(houseModel.statusName?houseModel.statusName:"未成交")+']';
				document.querySelector('#txtTitle').innerHTML = houseModel.area+houseModel.buildingName+houseModel.buildNumber+'号楼'+houseModel.number+'室';
				document.querySelector('#txtCollectNum').innerHTML = houseModel.collectionTotal>0?houseModel.collectionTotal:0;
//				document.querySelector('#txtBargainNum').innerHTML = houseModel.bargainTotal>0?houseModel.bargainTotal:0;
//				if(tradeModel){
					if(_kind == 3){
//						console.log(tradeModel.leasePriceMonth);
						document.querySelector('.xa-trade-price').innerHTML = '租金';
						document.querySelector('#txtPrice').innerHTML = (houseModel.leasePriceMonth)+'元/月';
					}else{
						document.querySelector('.xa-trade-price').innerHTML = '成交金额';
						document.querySelector('#txtPrice').innerHTML = parseInt(houseModel.totalPrice/10000)+'万';
					}
					
					var strTime = houseModel.awardContractDate?js_date_time(houseModel.awardContractDate):'&nbsp;';
					document.querySelector('#txtTime').innerHTML = strTime;
//				}else{
//					if(_kind == 3){
//						document.querySelector('.xa-trade-price').innerHTML = '租金';
////						document.querySelector('#txtPrice').innerHTML = (tradeModel.leasePriceMonth)+'元/月';
//
//						document.querySelector('#txtPrice').innerHTML = '&nbsp;';
//					}else{
//						document.querySelector('.xa-trade-price').innerHTML = '成交金额';
//						document.querySelector('#txtPrice').innerHTML = '未成交';
//					}
//					document.querySelector('#txtTime').innerHTML = '&nbsp;';
//				}
				if(houseModel.tradingStateName){
					document.querySelector('#txtTradeState').innerHTML = houseModel.tradingStateName;
				}else{
					document.querySelector('#txtTradeState').innerHTML = '未成交';
				}
			};
			var createTradeStateFragment = function(listTradeState) {
				var fragment = document.createDocumentFragment();
				for(var i = 0; i < listTradeState.length; i++) {
					var div = document.createElement('div');
					div.className = 'xa-trade-state-cell';
					var stateData = listTradeState[i];
					var data = new Array();
					if(stateData.id<_tradingStateId){
						data.push('<img class="xa-trade-state-icon" src="../images/icon_check.png" />'); 
						data.push('<div class="xa-trade-state-checked">'); 
							
					}else if(stateData.id==_tradingStateId){
						data.push('<img class="xa-trade-state-icon" src="../images/icon_progressing.png" />'); 
						data.push('<div class="xa-trade-state-processing">'); 
						
					}else{
						data.push('<img class="xa-trade-state-icon" src="../images/icon_uncheck.png" />'); 
						data.push('<div class="xa-trade-state-uncheck">'); 
						
					}
					data.push('<div>'+stateData.description+'</div>');
					if(stateData.workDay>0){
						data.push('<div class="xa-trade-state-day">预计时间：'+stateData.workDay+'个工作日</div>');
					}
					data.push('</div>');
					div.innerHTML = data.join('');
					fragment.appendChild(div);
				}
				return fragment;
			};
			mui(".mui-scroll").on('tap','.xa-trade-connect-button',function(){
				var id = this.getAttribute("id");
				var mobile;
				
				mobile = document.querySelector('#txtBuyerMobile').innerHTML;
				if(mobile){
					var btnArray = ['拨打', '取消'];
					mui.confirm('是否拨打' + mobile + '?', '提示', btnArray, function(e) {
						if(e.index == 0) {
							plus.device.dial(mobile, false);
						}
					});
				}else{
					mui.toast('本次交易还没开始，还没有经纪人');
				}
				
			});
			var getTradeDetail = function(successCallback, failCallback) {
				var param = [{
					key: 'houseId',
					value: _houseModel.id
				}];
				var net = fjNetwork;
				net.get('fjzx/common/house-sale-detail.json', param, function(data) {
					//成功 
					successCallback(data.houseSaleDetail); 
				}, function(message) {
					//失败
					mui.toast(message);
					failCallback();
				});
			};
			
			
		</script>
	</body>

</html>